<?php
/*
 * <basefont color="red" size="5">  
 * <font size="3" color="red">This is some text!</font>
 * <font size="2" color="blue">This is some text!</font>
 * <font face="verdana" color="green">This is some text!</font> 
 * Big
 * center
 * font
 * s
 * strike
 * tt
 * u
 */
include_once 'Answer_Patterns.php';
include_once 'Mount_DOM_tree.php';

class Refactoring_Old_Tags_CSS extends Answer_Patterns {

   public function start($domDocument) {
      $result = "";
      $mount_tree = new Mount_DOM_tree();

      $allSearch = array($domDocument->getElementsByTagName('basefont'), $domDocument->getElementsByTagName('big'),
          $domDocument->getElementsByTagName('center'), $domDocument->getElementsByTagName('font'),
          $domDocument->getElementsByTagName('s'), $domDocument->getElementsByTagName('strike'),
          $domDocument->getElementsByTagName('tt'), $domDocument->getElementsByTagName('u'));

      foreach ($allSearch as $search) {
         foreach ($search as $f) {
            $answer = 'div';
            $atributos = ($f->getAttribute("id") ? ' id="' . $f->getAttribute("id") : '' );

            $style = "";
            switch ($f->nodeName) {
               case "basefont":
                  $style .= ($f->getAttribute("color") ? ' color : ' . $f->getAttribute("color") . '; ' : '' );
                  $style .= ($f->getAttribute("face") ? ' font-family : \'' . $f->getAttribute("face") . '\'; ' : '' );
                  $style .= ($f->getAttribute("size") ? ' font-size : ' . (9 + ($f->getAttribute("size") * 2)) . 'px; ' : '' );

                  $atributos .= ' style="' . $style . '"';
                  break;
               case "font":
                  $style .= ($f->getAttribute("color") ? ' color : ' . $f->getAttribute("color") . '; ' : '' );
                  $style .= ($f->getAttribute("face") ? ' font-family : \'' . $f->getAttribute("face") . '\'; ' : '' );
                  $style .= ($f->getAttribute("size") ? ' font-size : ' . (9 + ($f->getAttribute("size") * 2)) . 'px; ' : '' );

                  $atributos .= ' style="' . $style . ' ' . $f->getAttribute("style").'"';
                  break;
               case "big":
                  $atributos .= ($f->getAttribute("style") ? ' style="' . $f->getAttribute("style") . ' font-size:20px;"' 
                                 : ' style="font-size:20px;"' );
                  break;
               case "center":
                  $atributos .= ($f->getAttribute("style") ? ' style="' . $f->getAttribute("style") . ' text-align:center;"' 
                                 : ' style="text-align:center;"' );
                  break;
               case "s":
                  $atributos .= ($f->getAttribute("style") ? ' style="' . $f->getAttribute("style") . ' text-decoration: line-through;"' 
                                 : ' style="text-decoration: line-through;"' );
                  break;
               case "strike":
                  $atributos .= ($f->getAttribute("style") ? ' style="' . $f->getAttribute("style") . ' text-decoration: line-through;"' 
                                 : ' style="text-decoration: line-through;"' );
                  break;
               case "tt":
                  $atributos .= ($f->getAttribute("style") ? ' style="' . $f->getAttribute("style") . ' text-decoration: underline;"' 
                                 : ' style="font-family: Lucida Console, monospace"' );
                  break;
               case "u":
                  $atributos .= ($f->getAttribute("style") ? ' style="' . $f->getAttribute("style") . ' text-decoration: underline;"' 
                                 : ' style="text-decoration: underline;"' );
                  break;
            }

            $result .= parent::elementAnswerPatterns("&LT;$f->nodeName&GT;", $f->getLineNo(), "&LT;" . $answer . " style='...'/&GT;", 
                                 "Deve ser substituido por CSS,", " e não é mais utilizado");
            $result .= parent::tableAnswer($mount_tree->structHTML($f, 1, 0), 
                                 $mount_tree->structHTMLElementRefactory($f, 1, 0, "$answer", 0, $atributos));
         }
      }
      if (!empty($result)) {
         $result = parent::titleAnswerPatterns("Elementos que foram descontinuados porque seus efeitos são apenas visuais") . $result;
      }
      return $result;
   }

}

?>